package com.mall.common.config.zk;

import org.apache.curator.framework.CuratorFrameworkFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: xrj
 * @date: 2022/5/1 1:54
 * @description:
 */
@Configuration
@EnableConfigurationProperties(value = ZooKeeperClient.class)
@ConditionalOnClass(value = CuratorFrameworkFactory.class)
public class ZookeeperConfig {
    public static final Logger logger = LoggerFactory.getLogger(CuratorFrameworkFactory.class);

    @Autowired
    ZooKeeperClient zooKeeperClient;

    @Bean
    public CuratorFrameworkClient createCuratorFrameworkClient() {
        logger.info(zooKeeperClient.toString());
        return new CuratorFrameworkClient(zooKeeperClient);
    }
}
